/* 
 * File:   Smoke.cpp
 * Author: cjjonker
 * 
 * Created on 20 december 2012, 16:07
 */

#include "Smoke.h"
#include "GL/glut.h"
#include "Dataset.h"
#include "ScalarDataset.h"

Smoke::Smoke()
{
    d_name = "Smoke visualization";
}

void Smoke::draw(int winW, int winH)
{
    int        i, j, idx; 
    double px,py;
    const int DIM = d_simulation->getDim();
    
    fftw_real  wn = (fftw_real)winW / (fftw_real)(DIM + 1);   // Grid cell width
    fftw_real  hn = (fftw_real)winH / (fftw_real)(DIM + 1);  // Grid cell heigh

    setColormapMinMax();
    
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    
    for (j = 0; j < DIM - 1; j++)			//draw smoke
    {
        glBegin(GL_TRIANGLE_STRIP);

            i = 0;
            px = wn + (fftw_real)i * wn;
            py = hn + (fftw_real)j * hn;
            idx = (j * DIM) + i;
            setGLColor(idx);
            glVertex2f(px, py);

            for (i = 0; i < DIM - 1; i++)
            {
                px = wn + (fftw_real)i * wn;
                py = hn + (fftw_real)(j + 1) * hn;
                idx = ((j + 1) * DIM) + i;
                setGLColor(idx);
                
                glVertex2f(px, py);
                px = wn + (fftw_real)(i + 1) * wn;
                py = hn + (fftw_real)j * hn;
                idx = (j * DIM) + (i + 1);
                setGLColor(idx);
                
                glVertex2f(px, py);
            }

            px = wn + (fftw_real)(DIM - 1) * wn;
            py = hn + (fftw_real)(j + 1) * hn;
            idx = ((j + 1) * DIM) + (DIM - 1);
            setGLColor(idx);
            glVertex2f(px, py);
        glEnd();
    }
}

